{extend name="layout/detail" /}

{block name="content"}
<div class="td-content-wrap p20">
    <div class="td-content-header">
        <h1 class="main-title">{$group.name}</h1>
    </div>
    <hr>
    <div class="layui-form panel">
        <a class="layui-btn" onclick="go_return_url();">返回</a>
        <span class="mid"></span>
        <a class="layui-btn" onclick="add();">添加</a>
    </div>
    <table class="layui-table column" lay-skin="line" id="layui_table">
        <thead>
            <tr>
                <th>序号</th>
                {volist name="field_list" id="field"}
                <th>{$field.field_name}</th>
                {/volist}
                <th>排序</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {php}
            $empty="
            <tr class='data-empty'>
                <td colspan='6'>无数据</td>
            </tr>
            ";
            {/php}
            {volist name="vo_list" id="vo" empty="$empty"}
            <tr>
                <td>{$vo.id}</td>
                {volist name="field_list" id="field"}
                <td>
                    {:widget('Field/read',[$field,$vo.value])}
                </td>
                {/volist}
                <td>{$vo.sort}</td>
                <td><a class="layui-btn layui-btn-xs" onclick="edit({$vo.id})">编辑</a><a
                        class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo['id']})">删除</a><a
                        class="layui-btn layui-btn-xs" onclick="sort_up({$vo.id})"><i class="fa fa-arrow-up"></i></a><a
                        class="layui-btn layui-btn-xs" onclick="sort_down({$vo.id})"><i
                            class="fa fa-arrow-down"></i></a>
                </td>
            </tr>
            {/volist}
        </tbody>
    </table>
</div>
{/block}

{block name="script"}
<script>
    layui.use(['form', 'element'], function () {
        let $ = layui.jquery;
        set_return_url();

        var fn = {
            index: function (module) {
                window.open('{:url("index")}', '_self');
            },
            add: function () {
                window.open('{:url("add")}?group_id={$group_id}', '_self');
            },
            edit: function (id) {
                window.open("{:url('edit')}?id=" + id, '_self');
            },
            del: function (id) {
                layer.msg('确定要删除吗?', {
                    time: 0,
                    btn: ['确定', '取消'],
                    yes: function (index) {
                        var vars = 'id=' + id;
                        $.get("{:url('del')}", vars, function (ret) {
                            if (ret.code) {
                                layer.msg(ret.msg, {
                                    time: 1200
                                }, function () {
                                    location.reload(true);
                                });
                            } else {
                                layer.msg(ret.msg, {
                                    time: 1200
                                });
                            }
                        });
                    },
                    no: function (index) {
                        layer.close(index);
                    }
                });
            },
            sort_up: function (id) {
                var vars = "id=" + id;
                $.get("{:url('sort_up')}", vars, function (data) {
                    if (data.code) {
                        layer.msg(data.msg, {
                            time: 1200
                        }, function () {
                            location.reload(true);
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                });
            },
            sort_down: function (id) {
                var vars = "id=" + id;
                $.get("{:url('sort_down')}", vars, function (data) {
                    if (data.code) {
                        layer.msg(data.msg, {
                            time: 1200
                        }, function () {
                            location.reload(true);
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                });
            }
        };
        win_exp(fn);

        var form = layui.form;
        form.on('select(test)', function (data) {
            $('#form_search').submit();
        });
    });
</script>
{/block}